package com.allwees.bs.c.module.order.dto;

import com.allwees.bs.c.module.base.dto.BaseDto;
import com.allwees.bs.c.module.order.entity.LogisticsWaybillEntity;
import com.allwees.bs.core.model.logistics.dto.TrackingDetail;
import com.allwees.core.common.util.json.JsonUtil;
import com.allwees.core.common.util.reflect.PojoUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 *
 *
 * @author yangylsky
 * @since 2019-09-06
 *
 */
@Slf4j
@Data
@EqualsAndHashCode(callSuper=false)
public class OrderLogisticsDTO extends BaseDto<OrderLogisticsDTO> {
	private String orderNo;

	/**
	 * 物流商代码
	 */
    private String carrierCode;

	/**
	 * 物流渠道代码
	 */
    private String channelCode;

	/**
	 * 运单号码
	 */
	private String expressCode;

	/**
	 * 运单内容明细(Json格式)
	 */
	private String expressDetail;

	/**
	 * 运单标签本地文件地址
	 */
	private String expressLabelFile;

	/**
	 * 运单标签远程文件URL
	 */
	private String expressLabelUrl;

	/**
	 * 运单物流跟踪明细
	 */
	private TrackingDetail trackingDetail;

    /**
     * 发货日期
     */
	private Date shippingDate;

    /**
     * 配送日期
     */
	private Date deliverDate;

	/**
	 * 运单物流跟踪明细最后更新时间
	 */
	private Date trackingModifyDate;

    private Date gmtCreate;

    private Date gmtModify;

    public static OrderLogisticsDTO fromEntity(LogisticsWaybillEntity entity) {
    	if(entity == null) {
    		return null;
    	}
    	OrderLogisticsDTO dto = PojoUtil.copyWithOmit(new OrderLogisticsDTO(), entity, "trackingDetail");
    	try {
			dto.setTrackingDetail(JsonUtil.fromJson(entity.getTrackingDetail(), TrackingDetail.class));
		}catch (Exception e){
			log.warn(">>>>>>>>>> logistics tracking detail,order item uuid:{}", entity.getOrderItemUuid(), e);
		}
    	return dto;
    }
}
